<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <div id="app">
    姓：<input type="text" v-model="fname"><br>
    名：<input type="text" v-model="lname"><br>
    <p>姓名：{{fulname}}</p>
    <button @click="cname">修改姓名</button>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        fname: "",
        lname: ""
      },
      computed: {
        // 简写
        // fulname() {
        //   return this.fname + this.lname
        // }
        // 完整写法
        fulname: {
          get() {
            return this.fname + this.lname
          },
          // 修改
          set(value) {
            this.fname = value.slice(0, 1)
            this.lname = value.slice(1)
          }
        }
      },
      methods: {
        cname() {
          this.fulname = prompt("请输入：")
        }
      }
    })
  </script>
</body>

</html>